<?php


namespace App\Models;


use App\Models\Pay\PayFactory;
use App\Models\Recharge\Recharge;
use App\User;
use Illuminate\Http\Request;

class Balance
{
    public static function getNotifyUrl(Request $request, $order)
    {
        $url = $request->root();
        $root = '';
        if ($order->pay_type == 2) {
            $root = '/api/wxnotify';
        }
        return $url.$root;
    }

    public static function pay(Request $request)
    {
        $order = Order::find($request->order_id);
        ulog($order);
        if(!$order){
           uexception('订单不存在');
        }
        if ($order['total_amount'] <= 0) {
            uexception('支付金额不能小于0');
        }
        $pay = PayFactory::create($order->pay_type);
        $nofiy_url = self::getNotifyUrl($request,$order);
        $result = $pay->pay($order, $nofiy_url);
        return $result;
    }
}